package com.esun.rabbit2.communicaters;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.DistributionChannels;
import com.esun.config.Key;
import com.esun.model.CurrentLotteryNumInfo;
import com.esun.model.UserInfo;
import com.esun.network.ServerCommunicater;
import com.esun.util.HashMapUtil;

public class CurrentLotteryNumCommunicater extends ServerCommunicater {
	private boolean isSucceed = false;
	public boolean isGetCurrentLotteryNumSucceed (String lotId) throws ClientProtocolException, IOException, ParserConfigurationException,
	SAXException {
		ArrayList<HashMap<String, String>> arraylist = new ArrayList<HashMap<String, String>>();
		arraylist.add(HashMapUtil.getMapItem(BussinessCode.PASER_MID, BussinessCode.MID_FUCAI3D_TIMELEFT));
		arraylist.add(HashMapUtil.getMapItem(BussinessCode.PASER_CK, UserInfo.getUserInfo().getUserSession()));//CK
		arraylist.add(HashMapUtil.getMapItem(Key.KEY_CHANNEL, DistributionChannels.QUDAO));//渠道号
		arraylist.add(HashMapUtil.getMapItem(Key.KEY_LOTID, lotId));//彩种：北京足球单场
		super.getServerResponse(arraylist, true);
		if (super.getState() == 100) {// 通信成功返回100
			isSucceed = true;
		}else{
			isSucceed = false;
		}
		return isSucceed;
	}
	public ArrayList<CurrentLotteryNumInfo> getCurrentLotteryNum () {
		ArrayList<CurrentLotteryNumInfo> listCurrentLotteryNumInfos = new ArrayList<CurrentLotteryNumInfo>();
		ArrayList<Hashtable<String, String>> list = new ArrayList<Hashtable<String, String>>();
		list = super.getListResult();
		if (list != null) {
			int count = list.size();
			for (int i = 0; i < count; i++) {
				Hashtable<String, String> hashtable = new Hashtable<String, String>();
				hashtable = list.get(i);
				CurrentLotteryNumInfo currentLotteryNumInfo = CurrentLotteryNumInfo.getCurrentLotteryNumInfo();
				currentLotteryNumInfo.setLotid(hashtable.get(Key.KEY_LOTID));
				currentLotteryNumInfo.setShowtype(hashtable.get(Key.KEY_SHOWTYPE));
				currentLotteryNumInfo.setActive(hashtable.get(Key.KEY_ACTIVE));
				currentLotteryNumInfo.setAddmoney(hashtable.get(Key.KEY_ADDMONEY));
				currentLotteryNumInfo.setExpect(hashtable.get(Key.KEY_EXPECT));
				currentLotteryNumInfo.setLastopencode(hashtable.get(Key.KEY_LASTOPENCODE));
				currentLotteryNumInfo.setLefttime(hashtable.get(Key.KEY_LEFTTIME));
				currentLotteryNumInfo.setMoney(hashtable.get(Key.KEY_MONEY));
				currentLotteryNumInfo.setBuyendtime(hashtable.get(Key.KEY_BUYENDTIME));
				currentLotteryNumInfo.setLastexpect(hashtable.get(Key.KEY_LASTEXPECT));
				currentLotteryNumInfo.setLastopentime(hashtable.get(Key.KEY_LASTOPENTIME));
				listCurrentLotteryNumInfos.add(currentLotteryNumInfo);
			}
		}
		return listCurrentLotteryNumInfos;
	}
}
